trigger CreateOutletAuditHistory on OutletAuditHistory__c (before insert, before update) {
    
        list<id> auditISVID=new list<id>();
        list<id> ProductId=new list<id>();
        
        for(OutletAuditHistory__c c:trigger.new){
            auditISVID.add(c.In_store_visit_id__c);
            ProductId.add(c.Product__c);
        }
        
        list<Inventory__c> InventoryList=[select id,Product_Name__c,in_store_visit__c from Inventory__c where Product_Name__c in:ProductId and in_store_visit__c in:auditISVID limit 100];
        map<string,id>  InventoryMap=new map<string,id>();
        
        for( Inventory__c i: InventoryList){
             InventoryMap.put(''+string.valueof(i.Product_Name__c).substring(0,15)+string.valueof(i.in_store_visit__c).substring(0,15),i.id);
        }
        
        
        for(OutletAuditHistory__c o:trigger.new){
            if(o.audit__c != null){
                if(InventoryMap.containskey(''+string.valueof(o.Product__c).substring(0,15)+string.valueof(o.In_store_visit_id__c).substring(0,15))){
                    o.Outlet_Distribution_Information__c =InventoryMap.get(''+string.valueof(o.Product__c).substring(0,15)+string.valueof(o.In_store_visit_id__c).substring(0,15));
                }
         
            }
        }    
    
    
}